home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4085 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.Stanford.EDU!microunity!toms
  3. From: toms@MicroUnity.com (Tom Sanders)
  4. Subject: Re: Float calculations
  5. Message-ID: <DM458u.F1y@microunity.com>
  6. Sender: usenet@microunity.com (news id)
  7. Organization: MicroUnity Systems Engineering, Inc.
  8. References:  <4eqssf$d9q@camelot.ccs.neu.edu>
  9. Date: Thu, 1 Feb 1996 20:07:42 GMT
  10.  
  11. In article <4eqssf$d9q@camelot.ccs.neu.edu>, jason@ccs.neu.edu (Jason Leatherman) writes:
  12. |> 
  13. |> Hi,
  14. |> 
  15. |>   Check out the results I get when running this simple program on a
  16. |> Sparc/UNIX system, compiled with gcc:
  17. |> 
  18. |> #include <stdio.h>
  19. |> 
  20. |> void main()
  21. |> {
  22. |>   float a, b;
  23. |> 
  24. |>   printf("%0.10f  %0.10f  %0.10f\n", 99974.0, 50.0, 99974.0/50.0);
  25. |> 
  26. |>   a = 99974.0;
  27. |>   b = 50.0;
  28. |>   printf("%0.10f  %0.10f  %0.10f\n", a, b, a/b);
  29. |> }
  30. |> 
  31. |> The output is:
  32. |> 99974.0000000000  50.0000000000  1999.4800000000
  33. |> 99974.0000000000  50.0000000000  1999.4799804688
  34. |> 
  35. |>   Why do the divisions produce different results?  This is probably some
  36. |> simple thing that I've forgotten, but I haven't figured it out yet.  Does
  37. |> anyone know?  Note that compiling with the -ffloat-store flag didn't make
  38. |> a difference.
  39. |>   Thanks for any help,
  40. |> 
  41. |> Jason
  42.  
  43. For what it's worth, cc on both HP and Sun workstations do not behave
  44. this way, but gcc on both machines do.  
  45.  
  46. Tom Sanders
  47.